package cn.goktech.edu.service.impl;

import cn.goktech.edu.entity.Teacher;
import cn.goktech.edu.entity.vo.TeacherQuery;
import cn.goktech.edu.mapper.TeacherMapper;
import cn.goktech.edu.service.TeacherService;
import cn.goktech.util.ResultUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * <p>
 * 讲师 服务实现类
 * </p>
 *
 * @author carter
 * @since 2021-01-25
 */
@Service
public class TeacherServiceImpl extends ServiceImpl<TeacherMapper, Teacher> implements TeacherService {
    @Override
    public void getTeacherPageCondition(Page<Teacher> pageParam, TeacherQuery teacherQuery) {
        //处理参数并构建查询条件
        QueryWrapper<Teacher> tWrapper = new QueryWrapper<>();
        //处理参数
        String name = teacherQuery.getName(); //讲师名字
        Integer level = teacherQuery.getLevel();//讲师等级
        String begin = teacherQuery.getBegin();//加入时间
        String end = teacherQuery.getEnd();//最后修改时间

        //效率优化：
        if(teacherQuery==null){
            baseMapper.selectPage(pageParam,null);
            return;
        }

        if(!StringUtils.isEmpty(name)){
            tWrapper.like("name",name);
        }
        if(!StringUtils.isEmpty(level)){
            tWrapper.eq("level",level);
        }
        if(!StringUtils.isEmpty(begin)){
            tWrapper.ge("gmt_create",begin);
        }
        if(!StringUtils.isEmpty(end)){
            tWrapper.le("gmt_modified",end);
        }

        //查询
        baseMapper.selectPage(pageParam,tWrapper);
        //由于结果集自动封装在pageParam中，不用返回
    }
}
